home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / Everything / Checkboxes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  12.9 KB  |  509 lines  |  [TEXT/CWIE]

  1. /* Checkboxes.c */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15. #include <stdlib.h>
  16.  
  17. #include "Globals.h"
  18. #include "ResourceDefs.h"
  19. #include "DoScrap.h"
  20. #include "Miscellany.h"
  21. #include "Scrolling.h"
  22. #include "ControlUtils.h"
  23. #include "Dispatcher.h"
  24. #include "DDocData.h"
  25. #include "EverythingEngine.h"
  26. #include "EverythingDoc.h"
  27. #include "Checkboxes.h"
  28.  
  29.  
  30. static    EverythingEngine*      GetEngine    (Checkboxes*    self);
  31.  
  32. static    void    DoUndo        (Checkboxes*    self);
  33. static    void    DoCut        (Checkboxes*    self);
  34. static    void    DoCopy        (Checkboxes*    self);
  35. static    void    DoPaste        (Checkboxes*    self);
  36. static    void    DoClear        (Checkboxes*    self);
  37. static    void    DoSelectAll        (Checkboxes*    self);
  38. static    void    DoShowClipboard    (Checkboxes*    self);
  39.  
  40.  
  41. //----------
  42. Checkboxes*        NewCheckboxes ()
  43. {
  44.     Checkboxes*        window;
  45.  
  46.     window = (Checkboxes*)malloc (sizeof (Checkboxes));
  47.     Checkboxes_Init (window);
  48.     SetClassID (window, classCheckboxes);
  49.  
  50.     return window;
  51. }
  52.  
  53. //----------
  54. void    DeleteCheckboxes (
  55.     Checkboxes*        window)
  56. {
  57.     Checkboxes_Free (window);
  58.     free (window);
  59. }
  60.  
  61. //----------
  62. void    Checkboxes_Create (
  63.     AMDoc*            inDoc,
  64.     DDocData*        inData)
  65. {
  66.     Checkboxes*        winObj = NewCheckboxes ();
  67.  
  68.     if (winObj != nil) {
  69.         Checkboxes_Open (winObj, inDoc, inData);
  70.     }
  71. }
  72.  
  73. //----------
  74. void    Checkboxes_Init (
  75.     Checkboxes*        self)
  76. {
  77. }
  78.  
  79. //----------
  80. void    Checkboxes_Free (
  81.     Checkboxes*        self)
  82. {
  83. }
  84.  
  85. //----------
  86. EverythingEngine*    GetEngine (
  87.     Checkboxes*        self)
  88. {
  89.     return (EverythingEngine*) self->super.mDoc->mEngine;
  90. }
  91.  
  92. /*----------*/
  93. void    Checkboxes_Open (
  94.     Checkboxes*        self,
  95.     AMDoc*            inDoc,
  96.     DDocData*        inData)
  97. {
  98.     WindowPtr        window;
  99.     Handle            wftb;
  100.  
  101.     self->super.mDoc = inDoc;
  102.     self->mData = inData;
  103.     AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  104.  
  105.     window = GetNewCWindow (WIND_Checkboxes, nil, (WindowPtr) -1L);
  106.     if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
  107.         SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
  108.     }
  109.     self->super.mWindow = window;
  110.     ((EverythingDoc*)self->super.mDoc)->mCheckboxesPtr = window;
  111.  
  112.     SetWindowKind (window, 'AM');
  113.     SetWRefCon (window, (long) self);
  114.     SetPort (window);
  115.     SetInfo (window);
  116.  
  117.     wftb = GetResource ('Wftb', WIND_Checkboxes);
  118.  
  119.     CreateRootControl (window, &self->super.mRootControl);
  120.  
  121.     self->super.vScroll = nil;
  122.     self->super.hScroll = nil;
  123.  
  124.  
  125.     self->mStandard2Handle = GetNewControl (CNTL_Standard2, window);
  126.     SetWindowItemFont (self->mStandard2Handle, wftb, 1);
  127.     SetControlValue (self->mStandard2Handle, GetStandard (self->mData));
  128.  
  129.     self->mXxHandle = GetNewControl (CNTL_Xx, window);
  130.     SetWindowItemFont (self->mXxHandle, wftb, 2);
  131.     SetControlValue (self->mXxHandle, GetXx (self->mData));
  132.  
  133.     self->mCapTriangleLabel = GetNewControl (CNTL_CapTriangle, window);
  134.     SetWindowItemFont (self->mCapTriangleLabel, wftb, 3);
  135.     SetControlFromTEXT (self->mCapTriangleLabel, TEXT_CapTriangle);
  136.  
  137.     self->mGraphic2Handle = GetNewControl (CNTL_Graphic2, window);
  138.     SetWindowItemFont (self->mGraphic2Handle, wftb, 4);
  139.  
  140.     self->mCapcicn2Label = GetNewControl (CNTL_Capcicn2, window);
  141.     EmbedControl (self->mCapcicn2Label, self->mGraphic2Handle);
  142.     SetWindowItemFont (self->mCapcicn2Label, wftb, 5);
  143.     SetControlFromTEXT (self->mCapcicn2Label, TEXT_Capcicn2);
  144.  
  145.     self->mLight2Handle = GetNewControl (CNTL_Light2, window);
  146.     EmbedControl (self->mLight2Handle, self->mGraphic2Handle);
  147.     SetWindowItemFont (self->mLight2Handle, wftb, 6);
  148.     SetControlValue (self->mLight2Handle, GetLight (self->mData));
  149.  
  150.     self->mCapicl10Label = GetNewControl (CNTL_Capicl10, window);
  151.     EmbedControl (self->mCapicl10Label, self->mGraphic2Handle);
  152.     SetWindowItemFont (self->mCapicl10Label, wftb, 7);
  153.     SetControlFromTEXT (self->mCapicl10Label, TEXT_Capicl10);
  154.  
  155.     self->mLight3Handle = GetNewControl (CNTL_Light3, window);
  156.     EmbedControl (self->mLight3Handle, self->mGraphic2Handle);
  157.     SetWindowItemFont (self->mLight3Handle, wftb, 8);
  158.     SetControlValue (self->mLight3Handle, GetLight2 (self->mData));
  159.  
  160.     self->mCapicl11Label = GetNewControl (CNTL_Capicl11, window);
  161.     EmbedControl (self->mCapicl11Label, self->mGraphic2Handle);
  162.     SetWindowItemFont (self->mCapicl11Label, wftb, 9);
  163.     SetControlFromTEXT (self->mCapicl11Label, TEXT_Capicl11);
  164.  
  165.     self->mIcl8NextHandle = GetNewControl (CNTL_Icl8Next, window);
  166.     EmbedControl (self->mIcl8NextHandle, self->mGraphic2Handle);
  167.     SetWindowItemFont (self->mIcl8NextHandle, wftb, 10);
  168.     SetControlValue (self->mIcl8NextHandle, GetIcl8Next (self->mData));
  169.  
  170.     self->mCapICN2Label = GetNewControl (CNTL_CapICN2, window);
  171.     EmbedControl (self->mCapICN2Label, self->mGraphic2Handle);
  172.     SetWindowItemFont (self->mCapICN2Label, wftb, 11);
  173.     SetControlFromTEXT (self->mCapICN2Label, TEXT_CapICN2);
  174.  
  175.     self->mLR3Handle = GetNewControl (CNTL_LR3, window);
  176.     EmbedControl (self->mLR3Handle, self->mGraphic2Handle);
  177.     SetWindowItemFont (self->mLR3Handle, wftb, 12);
  178.     SetControlValue (self->mLR3Handle, GetLR3 (self->mData));
  179.  
  180.     self->mCapPICT2Label = GetNewControl (CNTL_CapPICT2, window);
  181.     EmbedControl (self->mCapPICT2Label, self->mGraphic2Handle);
  182.     SetWindowItemFont (self->mCapPICT2Label, wftb, 13);
  183.     SetControlFromTEXT (self->mCapPICT2Label, TEXT_CapPICT2);
  184.  
  185.     self->mLR4Handle = GetNewControl (CNTL_LR4, window);
  186.     EmbedControl (self->mLR4Handle, self->mGraphic2Handle);
  187.     SetWindowItemFont (self->mLR4Handle, wftb, 14);
  188.     SetControlValue (self->mLR4Handle, GetLR4 (self->mData));
  189.  
  190.     self->mBevel2Handle = GetNewControl (CNTL_Bevel2, window);
  191.     SetWindowItemFont (self->mBevel2Handle, wftb, 15);
  192.  
  193.     self->mNextAloneHandle = GetNewControl (CNTL_NextAlone, window);
  194.     EmbedControl (self->mNextAloneHandle, self->mBevel2Handle);
  195.     SetWindowItemFont (self->mNextAloneHandle, wftb, 16);
  196.     SetControlValue (self->mNextAloneHandle, GetNextAlone (self->mData));
  197.     SetBevelButtonGraphicAlignment (self->mNextAloneHandle, kControlBevelButtonAlignCenter, 0, 0);
  198.  
  199.     self->mNext3Handle = GetNewControl (CNTL_Next3, window);
  200.     EmbedControl (self->mNext3Handle, self->mBevel2Handle);
  201.     SetWindowItemFont (self->mNext3Handle, wftb, 17);
  202.     SetControlValue (self->mNext3Handle, GetNext (self->mData));
  203.     SetBevelButtonTextPlacement (self->mNext3Handle, kControlBevelButtonPlaceToRightOfGraphic);
  204.     SetBevelButtonTextAlignment (self->mNext3Handle, kControlBevelButtonAlignTextFlushLeft, 0);
  205.     SetBevelButtonGraphicAlignment (self->mNext3Handle, kControlBevelButtonAlignLeft, 0, 0);
  206.  
  207.     self->mNext4Handle = GetNewControl (CNTL_Next4, window);
  208.     EmbedControl (self->mNext4Handle, self->mBevel2Handle);
  209.     SetWindowItemFont (self->mNext4Handle, wftb, 18);
  210.     SetControlValue (self->mNext4Handle, GetNext2 (self->mData));
  211.     SetBevelButtonTextPlacement (self->mNext4Handle, kControlBevelButtonPlaceBelowGraphic);
  212.     SetBevelButtonTextAlignment (self->mNext4Handle, kControlBevelButtonAlignTextCenter, 0);
  213.     SetBevelButtonGraphicAlignment (self->mNext4Handle, kControlBevelButtonAlignTop, 0, 0);
  214.  
  215.     AdvanceKeyboardFocus (window);
  216.  
  217.     ShowWindow (window);
  218. }
  219.  
  220. /*----------*/
  221. void    Checkboxes_Close (
  222.     Checkboxes*        self)
  223. {
  224.     RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  225.  
  226.     ((EverythingDoc*)self->super.mDoc)->mCheckboxesPtr = nil;
  227.     SetInfo (nil);
  228.     HideWindow (self->super.mWindow);
  229.     DisposeWindow (self->super.mWindow);
  230.  
  231.     DeleteCheckboxes (self);
  232. }
  233.  
  234. /*----------*/
  235. void    Checkboxes_Track (
  236.     Checkboxes*        self,
  237.     ControlHandle    whichControl,
  238.     short            whichPart,
  239.     Point            where)
  240. {
  241.     Rect            bounds;
  242.     short            newValue;
  243.  
  244.     if (whichControl == self->mStandard2Handle) {
  245.         if (TrackCheckbox (self->mStandard2Handle, where)) {
  246.             SetStandard (self->mData, GetControlValue (self->mStandard2Handle) != 0);
  247.         }
  248.     }
  249.     if (whichControl == self->mXxHandle) {
  250.         if (TrackCheckbox (self->mXxHandle, where)) {
  251.             SetXx (self->mData, GetControlValue (self->mXxHandle) != 0);
  252.         }
  253.     }
  254.     if (whichControl == self->mLight2Handle) {
  255.         if (TrackCheckbox (self->mLight2Handle, where)) {
  256.             SetLight (self->mData, GetControlValue (self->mLight2Handle) != 0);
  257.         }
  258.     }
  259.     if (whichControl == self->mLight3Handle) {
  260.         if (TrackCheckbox (self->mLight3Handle, where)) {
  261.             SetLight2 (self->mData, GetControlValue (self->mLight3Handle) != 0);
  262.         }
  263.     }
  264.     if (whichControl == self->mIcl8NextHandle) {
  265.         if (TrackCheckbox (self->mIcl8NextHandle, where)) {
  266.             SetIcl8Next (self->mData, GetControlValue (self->mIcl8NextHandle) != 0);
  267.         }
  268.     }
  269.     if (whichControl == self->mLR3Handle) {
  270.         if (TrackCheckbox (self->mLR3Handle, where)) {
  271.             SetLR3 (self->mData, GetControlValue (self->mLR3Handle) != 0);
  272.         }
  273.     }
  274.     if (whichControl == self->mLR4Handle) {
  275.         if (TrackCheckbox (self->mLR4Handle, where)) {
  276.             SetLR4 (self->mData, GetControlValue (self->mLR4Handle) != 0);
  277.         }
  278.     }
  279.     if (whichControl == self->mNextAloneHandle) {
  280.         if (TrackClick (self->mNextAloneHandle, where)) {
  281.             SetNextAlone (self->mData, GetControlValue (self->mNextAloneHandle) != 0);
  282.         }
  283.     }
  284.     if (whichControl == self->mNext3Handle) {
  285.         if (TrackClick (self->mNext3Handle, where)) {
  286.             SetNext (self->mData, GetControlValue (self->mNext3Handle) != 0);
  287.         }
  288.     }
  289.     if (whichControl == self->mNext4Handle) {
  290.         if (TrackClick (self->mNext4Handle, where)) {
  291.             SetNext2 (self->mData, GetControlValue (self->mNext4Handle) != 0);
  292.         }
  293.     }
  294. }
  295.  
  296. //----------
  297. void    Checkboxes_DataChanged (
  298.     Checkboxes*        self,
  299.     long            inDataID)
  300. {
  301.     if (inDataID == idStandard) {
  302.         SetControlValue (self->mStandard2Handle, GetStandard (self->mData));
  303.     }
  304.     if (inDataID == idXx) {
  305.         SetControlValue (self->mXxHandle, GetXx (self->mData));
  306.     }
  307.     if (inDataID == idLight) {
  308.         SetControlValue (self->mLight2Handle, GetLight (self->mData));
  309.     }
  310.     if (inDataID == idLight2) {
  311.         SetControlValue (self->mLight3Handle, GetLight2 (self->mData));
  312.     }
  313.     if (inDataID == idIcl8Next) {
  314.         SetControlValue (self->mIcl8NextHandle, GetIcl8Next (self->mData));
  315.     }
  316.     if (inDataID == idLR3) {
  317.         SetControlValue (self->mLR3Handle, GetLR3 (self->mData));
  318.     }
  319.     if (inDataID == idLR4) {
  320.         SetControlValue (self->mLR4Handle, GetLR4 (self->mData));
  321.     }
  322.     if (inDataID == idNextAlone) {
  323.         SetControlValue (self->mNextAloneHandle, GetNextAlone (self->mData));
  324.     }
  325.     if (inDataID == idNext) {
  326.         SetControlValue (self->mNext3Handle, GetNext (self->mData));
  327.     }
  328.     if (inDataID == idNext2) {
  329.         SetControlValue (self->mNext4Handle, GetNext2 (self->mData));
  330.     }
  331. }
  332.  
  333. /*----------*/
  334. void    Checkboxes_MouseIn (
  335.     Checkboxes*        self,
  336.     Point            where,
  337.     short            modifiers)
  338. {
  339.     Rect        bounds;
  340.  
  341. }
  342.  
  343. //----------
  344. void    Checkboxes_ExitCurField (
  345.     Checkboxes*        self)
  346. {
  347.     ControlHandle    focus;
  348.  
  349.     GetKeyboardFocus (self->super.mWindow, &focus);
  350.  
  351.     if (focus == nil) {
  352.         // nothing to exit
  353.  
  354.     }
  355. }
  356.  
  357. /*----------*/
  358. void    Checkboxes_TypeIn (
  359.     Checkboxes*        self,
  360.     char            ch)
  361. {
  362.     ControlHandle    focus;
  363.     short            keyCode;
  364.  
  365.     GetKeyboardFocus (self->super.mWindow, &focus);
  366.  
  367.     if ((ch == charEnter)
  368.     ||  (ch == charReturn)) {
  369.         Checkboxes_ExitCurField (self);    // Dispatch
  370.     } else if (ch == charEsc) {
  371.     } else if (ch == charTab) {
  372.         AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
  373.     } else if (focus != nil) {
  374.         keyCode = curEvent.message & keyCodeMask;
  375.         HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
  376.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  377.     } else {
  378.         SysBeep (1);
  379.     }
  380. }
  381.  
  382. /*----------*/
  383. void    Checkboxes_Resize (
  384.     Checkboxes*        self)
  385. {
  386.     /* application-specific code to resize items in window */
  387. }
  388.  
  389. /*----------*/
  390. void    Checkboxes_Scroll (
  391.     Checkboxes*        self,
  392.     short            newValue,
  393.     short            oldValue)
  394. {
  395.     /* application-specific code to scroll window */
  396.     if (gWhichScroll == self->super.vScroll) {
  397.     } else {    // horizontal
  398.     }
  399. }
  400.  
  401. //----------
  402. void    DoUndo (
  403.     Checkboxes*        self)
  404. {
  405. } // DoUndo
  406.  
  407. //----------
  408. void    DoCut (
  409.     Checkboxes*        self)
  410. {
  411.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  412.  
  413.     if (curTE != nil) {
  414.         TECut (curTE);
  415.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  416.         scrapDirty = true;
  417.     }
  418. } // DoCut
  419.  
  420. //----------
  421. void    DoCopy (
  422.     Checkboxes*        self)
  423. {
  424.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  425.  
  426.     if (curTE != nil) {
  427.         TECopy (curTE);
  428.         scrapDirty = true;
  429.     }
  430. } // DoCopy
  431.  
  432. //----------
  433. void    DoPaste (
  434.     Checkboxes*        self)
  435. {
  436.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  437.  
  438.     if (curTE != nil) {
  439.         TEPaste (curTE);
  440.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  441.     }
  442. } // DoPaste
  443.  
  444. //----------
  445. void    DoClear (
  446.     Checkboxes*        self)
  447. {
  448.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  449.  
  450.     if (curTE != nil) {
  451.         TEDelete (curTE);
  452.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  453.     }
  454. } // DoClear
  455.  
  456. //----------
  457. void    DoSelectAll (
  458.     Checkboxes*        self)
  459. {
  460.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  461.  
  462.     if (curTE != nil) {
  463.         TESetSelect (0, 32767, curTE);
  464.     }
  465. } // DoSelectAll
  466.  
  467. //----------
  468. void    DoShowClipboard (
  469.     Checkboxes*        self)
  470. {
  471. } // DoShowClipboard
  472.  
  473. //----------
  474. Boolean        Checkboxes_DoCommand (
  475.     Checkboxes*        self,
  476.     long            inCommand)
  477. {
  478.     Boolean        result = true;
  479.  
  480.     switch (inCommand) {
  481.         case cmdUndo:
  482.                 DoUndo (self);
  483.             break;
  484.         case cmdCut:
  485.                 DoCut (self);
  486.             break;
  487.         case cmdCopy:
  488.                 DoCopy (self);
  489.             break;
  490.         case cmdPaste:
  491.                 DoPaste (self);
  492.             break;
  493.         case cmdClear:
  494.                 DoClear (self);
  495.             break;
  496.         case cmdSelectAll:
  497.                 DoSelectAll (self);
  498.             break;
  499.         case cmdShowClipboard:
  500.                 DoShowClipboard (self);
  501.             break;
  502.  
  503.         default:
  504.                 result = false;
  505.     } // switch
  506.  
  507.     return result;
  508. }
  509.